import Vue from 'vue'
import Vuex from 'vuex'
import dlqhttp from './common/http'

Vue.use(Vuex)

export default new Vuex.Store({
	state: {
		userInfo : {},
		menuList : [],
		systemName : '',
	},

	getters : {
		userInfo : state => state.userInfo,
		menuList : state => state.menuList,
		systemName : state => state.systemName,
	},

	mutations: {
		setUserInfo (state, obj) {
		    state.userInfo = obj.user;
		},
		setMenuList (state, obj) {
	        state.menuList = obj;
	    },
	    setSystemName (state, obj) {
	        state.systemName = obj;
	    },
	},

	actions: {
		getUserInfo ({ commit, dispatch}, para) {
			dlqhttp({
				fun : 'userInfo',
				requestType : 'get',
				cb : res => {
					commit('setUserInfo', res);
				}
			});
		},

		getMenuList ({ commit, dispatch}, para) {
			dlqhttp({
				fun : 'menuList',
				menu_id : para.menu_id,
				cb : res => {
					commit('setMenuList', res.list);
					commit('setSystemName', res.name);
				}
			});
		},
	}
})
